package com.boo.app;

import android.util.Log;
import java.util.Calendar;
import java.util.GregorianCalendar;

import android.app.*;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.content.Context;
import android.content.Intent;
import android.widget.DatePicker;
import android.widget.DatePicker.OnDateChangedListener;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;


public class term extends Activity implements OnDateChangedListener, OnTimeChangedListener{
	
	private AlarmManager mManager;
	private GregorianCalendar mCalendar;
	private DatePicker mDate;
	private TimePicker mTime;
	
	private NotificationManager mNotification;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        TextView textview = new TextView(this);
        textview.setText("This is the Albums tab");
        setContentView(textview);
        
        mNotification =(NotificationManager)getSystemService(NOTIFICATION_SERVICE);
        
        mManager=(AlarmManager)getSystemService(Context.ALARM_SERVICE);
        
        mCalendar= new GregorianCalendar();
        Log.i("HelloAlarmActivity",mCalendar.getTime().toString());
        
        setContentView(R.layout.term);
        Button b =(Button)findViewById(R.id.set);
        b.setOnClickListener(new View.OnClickListener(){
        	public void onClick (View v){
        		setAlarm();
        	}
        });
        
        mDate = (DatePicker)findViewById(R.id.date_picker);
        mDate.init (mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), 
        		mCalendar.get(Calendar.DAY_OF_MONTH),this);
        mTime =(TimePicker)findViewById(R.id.time_picker);
        mTime.setCurrentHour(mCalendar.get(Calendar.HOUR_OF_DAY));
        mTime.setCurrentMinute(mCalendar.get(Calendar.MINUTE));
        mTime.setOnTimeChangedListener(this);
    }
    
    private void setAlarm(){
    	mManager.set(AlarmManager.RTC_WAKEUP,mCalendar.getTimeInMillis(), pendingIntent());
    	Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
    	
    }
    
    private void resetAlarm(){
    	mManager.cancel(pendingIntent());
    }
    
    private PendingIntent pendingIntent(){
    	Intent i = new Intent(getApplicationContext(), term.class);
    	PendingIntent pi = PendingIntent.getActivity(this,0,i,0);
    	return pi;
    }
    
	public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
		// TODO Auto-generated method stub
    	mCalendar.set(year, monthOfYear, dayOfMonth, mTime.getCurrentHour(), mTime.getCurrentMinute());
    	Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
    }
		
	
	
	public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
		// TODO Auto-generated method stub
		mCalendar.set(mDate.getYear(), mDate.getMonth(), mDate.getDayOfMonth(), hourOfDay, minute);
		Log.i("HelloAlarmActivity", mCalendar.getTime().toString());
	}
		

	
}
